class Login {
    constructor() {
      this.btn = document.querySelector('.btn');
      this.username = document.querySelector('.form-control');
      this.password = document.querySelector('.password');
      this.remember = document.querySelector('.remember');
      this.state1 = false;//登录的状态
      this.divLogin();
      this.rememberThePassword();
    }
    // 登录
    divLogin() {
      this.btn.onclick = () => {
        let arr = JSON.parse(localStorage.getItem('info')) || [];
        if (arr.length == 0) {
          alert('该用户还没有注册，请注册！');
          location.href = 'register.html';
        } else {
          arr.forEach((item) => {
            if (this.username.value = item.username && this.password.value == item.password) {
              this.state1 = true;
            }
          })
        }
        if (this.state1) {
          alert('登录成功！即将跳转到首页');
          localStorage.setItem('login',JSON.stringify(arr));
          location.href = 'http://localhost:2206/index.html';
        } else {
          alert('用户名或密码错误');
          return
        }
      }
    }

    // 免登录
    rememberThePassword() {
      this.remember.onselect = () => {
        console.log(1111);
      }
    }
  }
  new Login()